{extend name="default/template/base_index" /}


{block name="area_header"}
<link type="text/css" rel="stylesheet" href="__CDN__/select2/4.0.0/css/select2.min.css" />
<script type="text/javascript" src="__CDN__/select2/4.0.0/js/select2.full.js"></script>
<script type="text/javascript" src="__CDN__/select2/4.0.0/js/i18n/zh-CN.js"></script>
{/block}

{block name="area_body"}
{include file="default/Widget/topbar" /}
<div class="admin-main container-fluid">
    {include file="default/Widget/left" /}
    <div class="admin-main-content">
        {include file="default/Widget/breadcrumb" /}
        <div class="table-responsive well ">

            <!-- Nav tabs -->


            <!-- Tab panes -->


                    <!-- 过滤\查询按钮 -->
                    <div class="filter-controls pull-left">
                        <form action="" class="addToGroupForm" method="post">
                            <input type="hidden" name="admin_id" value="{$uid}" />
                            <input type="hidden" name="group_id" value="{$groupid}" />
                            <!--<input  id="user_select2"  type="text" style="width:220px;padding: 10px 15px;" name="uid" class="form-control" />-->

                            <select style="width:220px;padding: 10px 15px;font-size: 15px;line-height: 1.42857143;" id="user_select2" name="uid" class="form-control">
                                <option></option>
                            </select>
                            <a id="addtogroup" target-form="addToGroupForm" class="ajax-post btn btn-sm btn-primary" href="{:url('AuthManage/new_binding')}">绑定本用户</a>
                        </form>
                    </div>


                </div>


            </div>

        </div>
    </div>
    <!-- END admin-main-content -->
</div>
<!-- END admin-main-->
{/block}

{block name="area_footer"}
<script type="text/javascript">

    $(function(){

        $("#groups").change(function(){
            $(".groupForm").submit();
        });
        $("#addtogroup").text("添加到"+$("#groups").find("option:selected").text());
        $("#user_select2").select2({
            placeholder: "输入用户uid或昵称查询"
            ,
            language: "zh-CN",
            ajax: {
                url: "{:url('Member/select')}",
                dataType: 'json',
                delay: 250,
                data: function (params) {
                    var queryParameters = {
                        q: params.term
                    };

                    return queryParameters;

                },
                processResults: function (result, page) {
                    console.log(result);
                    if(!result.data){
                        result.data = [];
                        result.data['nodata']="无相关数据";
                    }
                    // parse the results into the format expected by Select2.
                    // since we are using custom formatting functions we do not need to
                    // alter the remote JSON data
                    return {
                        results: result.data
                    };
                },
                cache: true
            },
            minimumInputLength: 0,
            templateSelection: function (repo) {
                return repo.nickname || repo.text;
            },
            templateResult: function (repo) {

                if (repo.loading) return repo.text;
                if(repo.nodata) return repo.nodata;
                var markup = '<div>[uid:'+repo.uid+'] '+repo.nickname+'</div>';
                return $(markup);
            },
        });


    })
</script>
{/block}